package org.datascooter.test.example;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.datascooter.utils.LangUtils;

/**
 * This class is purposed for testing transfer the all types of data by DataBaseContext STRING, LONG, BIGDECIMAL, TIMESTAMP, BOOLEAN, BLOB,CLOB, INT;
 * 
 * @author nemo
 * 
 */
public class ContextTestClassInt implements Serializable {

	private static final long serialVersionUID = 1481569024363272924L;
	private Long id;
	String stringValue;
	Long longValue;
	BigDecimal bigDecimalValue;
	Date timestampValue;
	Boolean booleanValue;
	Integer integerValue;

	public ContextTestClassInt() {
	}

	public ContextTestClassInt(Integer size, Long id) throws UnsupportedEncodingException {
		this.id = id;
		this.stringValue = LangUtils.repeat("1", size);
		this.longValue = new Long(size);
		this.bigDecimalValue = new BigDecimal(size);
		this.timestampValue = new Date();
		this.booleanValue = new Boolean(true);
		this.integerValue = size;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getStringValue() {
		return stringValue;
	}

	public void setStringValue(String stringValue) {
		this.stringValue = stringValue;
	}

	public Long getLongValue() {
		return longValue;
	}

	public void setLongValue(Long longValue) {
		this.longValue = longValue;
	}

	public BigDecimal getBigDecimalValue() {
		return bigDecimalValue;
	}

	public void setBigDecimalValue(BigDecimal bigDecimalValue) {
		this.bigDecimalValue = bigDecimalValue;
	}

	public Date getTimestampValue() {
		return timestampValue;
	}

	public void setTimestampValue(Date timestampValue) {
		this.timestampValue = timestampValue;
	}

	public Boolean getBooleanValue() {
		return booleanValue;
	}

	public void setBooleanValue(Boolean booleanValue) {
		this.booleanValue = booleanValue;
	}

	public Integer getIntegerValue() {
		return integerValue;
	}

	public void setIntegerValue(Integer integerValue) {
		this.integerValue = integerValue;
	}

	// @Override
	public Object[] flush() {
		return new Object[] {
				id, stringValue, longValue, bigDecimalValue, timestampValue, booleanValue, integerValue
		};
	}

	// @Override
	public void restore(Object[] fields) {
		id = Long.valueOf(fields[0] + "");
		this.stringValue = fields[1] + "";
		this.longValue = new Long(fields[2] + "");
		this.bigDecimalValue = new BigDecimal(fields[3] + "");
		try {
			this.timestampValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(fields[4] + "");
		} catch (ParseException e) {
			e.printStackTrace();
		}
		this.booleanValue = new Boolean(fields[5] + "");
		this.integerValue = new Integer(fields[6] + "");
		;
	}
}
